<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子27-JS进阶（三）</title>
    </head>
    <body>
        <pre>
            <code>
                    // 例子27

                    var pattern = /Java/g;
                    var text = 'JavaScript is more fun than Java!';
                    var result;
                    while((result = pattern.exec(text)) != null) {
                            alert('Matched "' + result[0] + '"' + ' at position ' + result.index + ';next search begins at ' + pattern.lastIndex);
                    }
                    // 弹窗结果：
                    // 第一次：Matched "Java" at position 0;next search begins at 4
                    // 第二次：Matched "Java" at position 28;next search begins at 32
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/27.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>